home *** CD-ROM | disk | FTP | other *** search
/ Sounds Terrific 1 / Sounds Terrific CD (1994)(Weird Science)(Disc 2 of 2)[!][Amiga-PC].iso / modules / g / greeny01.mod < prev    next >
Encoding:
Text File  |  1994-08-04  |  7.2 KB  |  287 lines

  1. Here goes, I guess...
  2. Greeny #8 @6910
  3. Thu Dec 12 05:38:34 1991
  4.                   RANDOM MULTI-LINE QUOTES AT MENU PROMPTS
  5.  
  6.                                 GREENY01.MOD
  7.                                 Version 1.00
  8.  
  9. Here's a mod that will allow random quotes at each main menu and transfer
  10. menu prompt.  It's mostly block read in, and unless you really want to you
  11. won't have to recompile your whole source code.
  12.  
  13. To edit the entire quote list (add quotes to the list, delete any quote from
  14. the list, or view the entire list) type //quoteedit from the main menu, or
  15. hit the quote key (") when it's waiting for a caller.  It will create and
  16. update a data file called RANQUOTE.DAT, in the gfiles directory.
  17.  
  18. To install the mod, do this:
  19.  
  20. 1) back up your source code.
  21.  
  22. 2) You must prototype the three new functions.  The easy way to do this
  23.    is to stick them into the beginning of the file BBS.C.  Right after the
  24.    line #define modem_time 3.5 is a good place.  The function prototypes look
  25.    like this:
  26.  
  27. void random_quote();
  28. char *get_random_quote();
  29. void thump();
  30.  
  31.    Just add them into your source code, each on a seperate line.
  32.  
  33. 3) Now find the function "void main()".  To do a search in Turbo C, or TC++,
  34.    Hit Control-Q Control-F, and type in void main() on the line it gives you.
  35.    Near the beginning of void main(), you'll find the following code.  Add
  36.    the line indicated.  (== means this line is already there, ++ means add
  37.    this line)
  38.  
  39.  
  40. ==  if ((sysstatus_expert & thisuser.sysstatus)==0)
  41. ==    printmenu(0);
  42. ==
  43. ==  nl();
  44. ++  thump(get_random_quote(),&abort);
  45. ==  nl();
  46. ==  tleft(1);
  47.  
  48. 4) About one screen down from the last change you should see this.  Add the
  49.    four lines indicated.
  50.  
  51. ==/**************************************************/
  52. ==  if (so()) {
  53. ++    if (strcmp(s,"QUOTEEDIT")==0) {
  54. ++      sysoplog("@ Ran QuoteEdit");
  55. ++      random_quote();
  56. ++    }
  57. ==    if (strcmp(s,"BOARDEDIT")==0) {
  58. ==      sysoplog("@ Ran Boardedit");
  59. ==      boardedit();
  60. ==    }
  61.  
  62.  
  63. 5) Next, search for the function "void dlmainmenu()" and insert the indicated
  64.    line, near the beginning.
  65.  
  66.  
  67. ==  if ((sysstatus_expert & thisuser.sysstatus)==0)
  68. ==    printmenu(3);
  69. ==
  70. ==  nl();
  71. ++  thump(get_random_quote(),&abort);
  72. ==  nl();
  73. ==  tleft(1);
  74.  
  75.  
  76. 6) Now search for the function "void getcaller()" and add these three lines.
  77.    (They're about three screens down from the beginning...)
  78.  
  79.  
  80. ==      switch(ch) {
  81. ++        case '\"':
  82. ++          if (ok_local()) random_quote();
  83. ++          break;
  84. ==        case '?':
  85. ==          if (ok_local()) {
  86.  
  87.  
  88. 7) Those are all the changes that need to be made to the existing code.  Now
  89.    we add some new functions.  These can be block read in if you don't feel
  90.    like typeing them.  (To block read something in, hit Control-K Control-R,
  91.    tell it the file name, and then hit Control-K Control-H to put the colors
  92.    back to normal.  Just block read in this entire mod at the end of BBS.C
  93.    and delete all the lines before and after the functions.  (Control-Y will
  94.    delete the line your cursor is currently on.)
  95.  
  96.  
  97. /* BEGINNING OF BLOCK READ FOR GREENY'S RANDOM QUOTE MOD */
  98.  
  99. void random_quote()
  100. {
  101.  
  102. #define QUOTE_LINES 3
  103. #define QUOTE_SIZE ((80*QUOTE_LINES)+1)
  104.  
  105.   long int f,f1,i,i1,i42,offset;
  106.   int done,abort;
  107.   char s[QUOTE_SIZE],s1[100],ch,ch1;
  108.  
  109.   done=0;
  110.   for(i=0; i<QUOTE_SIZE; i++) {
  111.   s[i]=0;
  112.   }
  113.   i=0;
  114.   do  {
  115.     abort=0;
  116.     prt(5,"Random Quotes - A)dd, L)ist, D)elete, Q)uit :");
  117.     ch=onek("QLAD");
  118.     switch(ch)  {
  119.       case 'Q':
  120.         done=1;
  121.         break;
  122.       case 'L':
  123.         outstr("\x0c");
  124.         nl();
  125.     prt(2,"Random Quotes Available");
  126.     nl();
  127.         prt(2,"-----------------------");
  128.     nl();
  129.         strcpy(s1,syscfg.gfilesdir);
  130.     strcat(s1,"RANQUOTE.DAT");
  131.     if((f=open(s1,O_RDONLY))==-1) {
  132.       close(f);
  133.       prt(3, "There are no quotes available.");
  134.       nl();
  135.       break;
  136.     }
  137.     lseek(f,0L,SEEK_SET);
  138.     i=filelength(f)/QUOTE_SIZE;
  139.     if (i == 0)  {
  140.       nl();
  141.       prt(3, "There are no quotes available.");
  142.       nl();
  143.       close(f);
  144.       break;
  145.     }
  146.     for (i1=0,(i=filelength(f)/QUOTE_SIZE); i1<i; i1++)
  147.       {
  148.       lseek(f,((long) (i1*QUOTE_SIZE)),SEEK_SET);
  149.       read(f,s,QUOTE_SIZE);
  150.       sprintf(s1,"%04d:",i1+1);
  151.       pla(s1,&abort);
  152.       thump(s,&abort);
  153.       if(abort) break;
  154.       }
  155.       nl();
  156.       close(f);
  157.       break;
  158.     case 'A':
  159.     nl();
  160.     prt(2,"Enter Random Quote...");
  161.     nl();
  162.          sprintf(s1,"Enter Random quote, %d lines maximum",QUOTE_LINES);
  163.         pl(s1);
  164.         s1[0]=0;
  165.         s[0]=0;
  166.         nl();
  167.         for (i=0; i<3; i++) {
  168.            npr("%d:",i+1);
  169.            mpl(77);
  170.            inli(s+strlen(s),s1,77,1);
  171.            if(s[0]==0) break;
  172.            if(s[strlen(s)-1]=='\n') break;
  173.        if(s[strlen(s)-1]==1) s[strlen(s)-1]=0;
  174.            strcat(s,"\n");
  175.         }
  176.     if(s[0]==0) {
  177.       nl();
  178.       prt(3, "Aborted");
  179.       nl();
  180.       break;
  181.     }
  182.     strcpy(s1,syscfg.gfilesdir);
  183.     strcat(s1,"RANQUOTE.DAT");
  184.     f=open(s1,O_RDWR | O_CREAT | O_BINARY,S_IREAD | S_IWRITE);
  185.     if(filelength(f))  {
  186.       lseek(f,-1L,SEEK_END);
  187.       read(f,((void *)&ch1),1);
  188.       if(ch1==26) lseek(f,-1L,SEEK_END);
  189.     }
  190.     s[QUOTE_SIZE-1]=0;
  191.     write(f,(void *)s,QUOTE_SIZE);
  192.     close(f);
  193.     break;
  194.       case 'D':
  195.     prt(6,"Number of quote to delete : ");
  196.     mpl(4);
  197.     inputl(s,4);
  198.     i42=atoi(s);
  199.     if(i42<1) break;
  200.     strcpy(s1,syscfg.gfilesdir);
  201.     strcat(s1,"RANQUOTE.DAT");
  202.     f=open(s1,O_RDWR | O_BINARY);
  203.     if(f>-1) {
  204.       i1=filelength(f);
  205.       if(i42>i1/QUOTE_SIZE) {
  206.         close(f);
  207.         break;
  208.       }
  209.       i42--;
  210.       lseek(f,(long) (i42 * QUOTE_SIZE), SEEK_SET);
  211.       read(f,s,QUOTE_SIZE);
  212.       nl();
  213.       nl();
  214.       thump(s,&abort);
  215.       nl();
  216.       prt(5,"Delete this Quote ?");
  217.       if (yn())  {
  218.         if(i42<(i1/QUOTE_SIZE)-1) {
  219.           for(i=i42; i<(i1/QUOTE_SIZE)-1; i++) {
  220.         lseek(f,(long) (QUOTE_SIZE * (i+1)),SEEK_SET);
  221.         read(f,(void *)s,QUOTE_SIZE);
  222.         lseek(f,(long) (QUOTE_SIZE * i),SEEK_SET);
  223.         write(f,(void *)s,QUOTE_SIZE);
  224.           }
  225.         }
  226.         chsize(f,(long) (i1-QUOTE_SIZE));
  227.         pl("Quote deleted");
  228.       }
  229.       close(f);
  230.     }
  231.     break;
  232.       }
  233.     } while ((!done) && (!hangup));
  234. }
  235.  
  236. char *get_random_quote()
  237. {
  238.   long int f,i,i1;
  239.   static char s1[QUOTE_SIZE];
  240.   char s[100];
  241.  
  242.   s1[0]=0;
  243.   strcpy(s,syscfg.gfilesdir);
  244.   strcat(s,"RANQUOTE.DAT");
  245.   if ((f=open(s,O_RDONLY))!=-1)
  246.     {
  247.     lseek(f,0L,SEEK_SET);
  248.     i=filelength(f)/QUOTE_SIZE;
  249.     if(i) {
  250.       i1=random(i);
  251.       lseek(f,(long)  (i1 * QUOTE_SIZE),SEEK_SET);
  252.       read(f,s1,QUOTE_SIZE);
  253.     }
  254.     close(f);
  255.   }
  256.   return s1;
  257. }
  258.  
  259. void thump(char *s, int *abort)
  260. {
  261.   int i=0,what=0;
  262.   while(s[i]) {
  263.     if(!(*abort)) {
  264.       if(s[i]=='\n') nl();
  265.       else outchr(s[i]);
  266.     }
  267.     checka(abort,& what);
  268.     i++;
  269.   }
  270. }
  271.  
  272. /* END OF BLOCK READ FOR GREENY'S RANDOM QUOTE MOD */
  273.  
  274. 8) Now save off the file by hitting F2, and compile it.  (If you haven't
  275.    figured out how to set up a decent project file, figure out how to do so
  276.    and in the mean time drop to dos and use random's make file.)
  277.  
  278. 9) Send me some email.  I have an account as user #8 at WWIVnet node @6910.
  279.  
  280. Until next time...
  281.  
  282. 3(GREENY)0
  283.  
  284. 9
  285. 9THE PROMISED LAND- Delran NJ  609-764-7144
  286. 86HOST OF SUB 42 - DEEP THOUGHT: THE INTERNATIONAL MENSA NET0
  287. 738400/ARQ/HST/HST/V32/V42/BIS